//
//  YDPerson.m
//  YDBASE
//
//  Created by rowena on 2019/9/24.
//  Copyright © 2019 wuyezhiguhun. All rights reserved.
//

#import "YDPerson.h"
#import <objc/runtime.h>
#import <objc/message.h>

@implementation YDPerson

+ (id)msgSendToObj:(id)obj Selector:(SEL)selector Prarms:(NSArray*)params NeedReturn:(BOOL)needReturn{
    id returnValue = nil;
    NSInteger paramsCount = params.count;
    NSMutableArray *params_M = [NSMutableArray arrayWithArray:params];
    //
    while (params_M.count < 5) {
        [params_M addObject:@""];
    }
    params = params_M;
    //
    if (obj && selector && [obj respondsToSelector:selector] && paramsCount <= 5) {
        if (needReturn) {
            returnValue = ((id (*) (id, SEL, id, id , id, id, id)) (void *)objc_msgSend) (obj, selector, params[0], params[1], params[2], params[3], params[4]);
        }else{
            ((void (*) (id, SEL, id, id , id, id, id)) (void *)objc_msgSend)(obj, selector,  params[0], params[1], params[2], params[3], params[4]);
        }
    }
    return returnValue;
}

+ (id)msgSendToClass:(Class)YSClass Selector:(SEL)selector Prarms:(NSArray*)params NeedReturn:(BOOL)needReturn{
    id returnValue = nil;
    NSInteger paramsCount = params.count;
    NSMutableArray *params_M = [NSMutableArray arrayWithArray:params];
    //
    while (params_M.count < 5) {
        [params_M addObject:@""];
    }
    params = params_M;
    //
    Method method = class_getClassMethod(YSClass, selector);
    //
    if (YSClass && selector && (int)method != 0 && paramsCount <= 5) {
        if (needReturn) {
            returnValue = ((id (*) (id, SEL, id, id , id, id, id)) (void *)objc_msgSend) (YSClass, selector, params[0], params[1], params[2], params[3], params[4]);
        }else{
            ((void (*) (id, SEL, id, id , id, id, id)) (void *)objc_msgSend)(YSClass, selector,  params[0], params[1], params[2], params[3], params[4]);
        }
    }
    return returnValue;
}

/**
 * 吃饭实例方法 无参数 无返回值
 */
- (void)personEat {
    NSLog(@"wuyezhiguhun -->: eat_person ");
}

/**
 * 吃饭类方法 无参数 无返回值
 */
+ (void)personEat {
    NSLog(@"wuyezhiguhun -->: eat_class ");
}

/**
 * 睡觉实例方法 有参数 无返回值
 * @pram hour 睡觉时间
 */
- (void)personSleepOfHour:(NSNumber *)hour {
    NSLog(@"wuyezhiguhun -->: sleep_persion -->: hour: %@", hour);
}

/**
 * 睡觉类方法 有参数 无返回值
 * @pram hour 睡觉时间
 */
+ (void)personSleepOfHour:(NSNumber *)hour {
    NSLog(@"wuyezhiguhun -->: sleep_class -->: hour: %@", hour);
}

/**
 * 是否吃饱实例方法 有参数 有返回值
 * @pram breadCount 待吃面包的数量
 * @return 返回是否吃饱 YES：吃饱 NO：没吃饱
 */
- (BOOL)personEatEnough:(NSNumber *)breadCount {
    
    NSLog(@"wuyezhiguhun -->: eatEnough_person -->: breadCount: %@", breadCount);
    
    return YES;
}

/**
 * 是否吃饱类方法 有参数 有返回值
 * @pram breadCount 待吃面包的数量
 * @return 返回是否吃饱 YES：吃饱 NO：没吃饱
 */
+ (BOOL)personEatEnough:(NSNumber *)breadCount {
    
    NSLog(@"wuyezhiguhun -->: eatEnough_person -->: breadCount: %@", breadCount);
    
    return YES;
}

@end
